<template>
  <div class="flex flex-col h-full">
    <SearchContainer @search="getData" @reset="() => (formState = {})">
      <a-form ref="formRef" class="flex" :model="formState" :colon="false" :label-col="{ style: { width: '70px' } }">
        <a-form-item name="zjm">
          <a-input v-model:value="formState.zjm" class="w-64" placeholder="编号/名称/助记码" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <!-- <div class=""> -->
      <!-- <a-button type="primary" class="mb-3 mr-2" @click="onClickEdit()">新增</a-button> -->
      <!-- </div> -->
      <BaseTable :loading="loading" column-code="000838" fill :data-source="tableData" bordered row-key="bh" :scroll="{ x: 2200 }" :pagination="pagination">
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'insureStatus'">
            <a-switch :checked="record.insureStatus" :un-checked-value="0" :checked-value="1" @change="onChangeInsureStatus(record)" />
          </template>
          <template v-if="column.dataIndex === 'mc'">
            <MedicineInfo :value="{ mc: record?.mc, gg: record?.gg, cj: record?.cj }" />
          </template>
          <template v-if="column.dataIndex === 'confineFlag'">
            {{ record.confineFlag === 1 ? '是' : '否' }}
          </template>
          <template v-if="column.dataIndex === 'subFlag'">
            {{ record.subFlag === 1 ? '是' : '否' }}
          </template>

          <template v-if="column.dataIndex === 'yxztStr'">
            <a-tag v-if="record.yxzt" color="red">停用</a-tag>
            <a-tag v-else color="blue">启用</a-tag>
          </template>
          <template v-if="column.dataIndex === 'jklbStr'">
            <div v-if="record.jklb === 1">医技项目</div>
            <div v-else-if="record.jklb === 4">检验项目</div>
            <div v-else-if="record.jklb === 3">理疗项目</div>
            <div v-else>普通项目</div>
          </template>
          <template v-if="column.dataIndex === 'action'">
            <a-button type="link" size="small" @click="onClickEdit(record)"> 修改 </a-button>
          </template>
        </template>
      </BaseTable>
    </a-card>
    <Edit v-model:open="editOpen" :row-data="rowData" @success="onSuceess" @confirm="editOpen = false" />
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { message } from 'ant-design-vue'
import SearchContainer from '@/components/SearchContainer'
import BaseTable from '@/components/BaseTable'
import Edit from './Edit.vue'

const rowData = ref({})
const editOpen = ref(false)
// const loading = ref(false)
// const tableData = ref([])
const formRef = ref(null)
const formState = ref({})
// const page = ref({ total: 0, current: 1, pageSize: 10 })

const onClickEdit = (row = {}) => {
  editOpen.value = true
  rowData.value = { ...row }
}
const onChangeInsureStatus = async (row) => {
  const status = row.insureStatus === 1 ? 0 : 1
  const { code, msg } = await post('/operation/opex/shanghai/doSaveShmiDictAdviceItems', { id: row.id, bh: row.bh, insureStatus: status })
  if (code !== 0) return message.error(msg)
  message.success(msg)
  getData()
}
const { loading, tableData, getData, pagination } = useTable({
  url: '/operation/opex/shanghai/getShmiDictAdviceItemsList',
  immediate: true,
  params: formState.value
})
// const queryList = async () => {
//   loading.value = true
//   const { code, data, total, msg } = await post('/operation/opex/shanghai/getShmiDictAdviceItemsList', {
//     mcbh: formState.value.mcbh,
//     pageNum: page.value.current,
//     pageSize: page.value.pageSize,
//     xmlb: formState.value.xmlb,
//     yxzt: formState.value.yxzt ? 0 : ''
//   })
//   if (code !== 0) return message.error(msg)
//   tableData.value = data
//   page.value.total = total
//   loading.value = false
// }
// const onPageChange = ({ current, pageSize }) => {
//   page.value.current = current
//   page.value.pageSize = pageSize
//   queryList()
// }
const onSuceess = () => {
  editOpen.value = false
  getData()
}
</script>
<style lang="less" scoped>
.ant-picker {
  width: 100%;
}
</style>
